package tmall.framework.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import tmall.framework.eobj.SegmentEobj;

import java.util.List;

@Mapper
public interface IdConfigMapper {

    @Select("SELECT name, max_id, step,description, update_time FROM tmall_id_config")
    @Results(value = {
            @Result(column = "name", property = "name"),
            @Result(column = "max_id", property = "maxId"),
            @Result(column = "step", property = "step"),
            @Result(column = "description", property = "description"),
            @Result(column = "update_time", property = "updateTime")

    })
    public List<SegmentEobj> queryAllSegment();

    @Insert("INSERT INTO tmall_id_config (name, max_id, step,description, update_time) VALUES ( #{name}, #{maxId}, #{step}, #{description},#{updateTime})")
    public int addSegment(SegmentEobj input);

    @Update("UPDATE tmall_id_config SET max_id = max_id + step WHERE name = #{tag}")
    public int updateMaxIdByKey(@Param("tag") String input);

    @Select("SELECT name, max_id, step,description, update_time FROM tmall_id_config where name =  #{tag}")
    @Results(value = {
            @Result(column = "name", property = "name"),
            @Result(column = "max_id", property = "maxId"),
            @Result(column = "step", property = "step"),
            @Result(column = "description", property = "description"),
            @Result(column = "update_time", property = "updateTime")

    })
    public SegmentEobj getSegmentByKey(@Param("tag") String input);

    @Update("UPDATE tmall_id_config SET max_id = max_id + step,SET step = #{step},description = #{description}, update_time = #{updateTime} WHERE name = #{name}")
    public int updateSegmentByKey(SegmentEobj input);

}
